package com.yang.util;

import java.sql.*;

/**
 * @author yangjiming
 * @create 2021-03-26 20:36
 */
public class JDBCUtil {
    private static String DRIVER="com.mysql.jdbc.Driver";
    private static String URL="jdbc:mysql://master:3306/shujia";
    private static String USERNAME="root";
    private static String PASSWORD="123456";

    static{
        try {
            Class.forName(DRIVER);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException {
        Connection conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
        return conn;
    }

    public static void closeAll(PreparedStatement ps,Connection conn) throws SQLException {
        ps.close();
        conn.close();
    }

    public static void closeAll(ResultSet rs,PreparedStatement ps,Connection conn) throws SQLException {
        rs.close();
        ps.close();
        conn.close();
    }

}
